<template>
  <el-form ref="form" :model="form" label-width="80px">

    <el-form-item label="审批附件" v-if="is_show_upload">
      <el-row>
        <el-col :span="18">
          <MyUploadFile
            ref="spFile"
            dir="approve"
            btn-name="审批附件"
            :files="form.fileList"
          ></MyUploadFile>
        </el-col>
      </el-row>
    </el-form-item>
    <el-form-item label="审批备注">
      <el-input
        type="textarea"
        v-model="form.note"
        maxlength="1500"
        show-word-limit
      >
      </el-input>
    </el-form-item>

    <el-form-item style="text-align: center;">
      <el-button type="primary" @click="pass(1)">通过</el-button>
      <el-button @click="pass(0)" type="danger">拒绝</el-button>
    </el-form-item>

  </el-form>
</template>

<script>
import {addShenPiLog, editProjectState} from '@/apilist/Project'
import uploadFile from "./uploadFile";
import MyUploadFile from "./MyUploadFile.vue";

export default {
  name: "spForm",
  data() {
    return {}
  },
  props: ['form'],
  components: {uploadFile, MyUploadFile},
  computed: {
    is_show_upload() {
      if (this.form.hasOwnProperty("is_show_upload")) {
        return this.form.is_show_upload;
      } else {
        return true;
      }
    },
  },
  methods: {
    async pass(state) {
      try {
        let request_data = {
          newData: this.form.newData,
          note: this.form.note,
          state: state,
          type: this.form.type,
        }
        if (this.is_show_upload) request_data['fileList'] = this.$refs.spFile.getNewFileList();
        console.log('request_data: ', request_data)
        const res = await addShenPiLog(request_data)
        const isChange = res.data.is_change
        if (isChange) {
          //消息弹窗
          this.$confirm(res.data.tips, '提示', {
            confirmButtonText: '确定',
            cancelButtonText: '取消',
            type: 'warning'
          }).then(() => {
          }).catch(() => {
            this.$message({
              type: 'info',
              message: '已取消'
            });
          });
        } else {
          //修改项目的流程
          let params = {id: this.form.newData.id, type: this.form.type, state: state}
          const result = await editProjectState(params)
          await this.$success(result.msg)
          location.reload()
        }
      }catch (e){
        Promise.reject(e)
      }
    },

    getSPFilesComputed() {
      return this.$refs.spFile.getNewFileList()
    },

  },

}
</script>

<style scoped>

</style>
